<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/6/24
  Time: 12:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>申请页面</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.5.7/css/layui.css">
</head>
<body>
<div class="layui-container" style="margin-top: 20px;">
    <form class="layui-form" lay-filter="applyForm" id="fm">
        <div class="layui-form-item">
            <label class="layui-form-label">申请提交时间</label>
            <div class="layui-input-inline" style="width: 200px">
                <input type="text" name="" id="" class="layui-input" lay-verify="required" placeholder="请选择申请提交时间">
            </div>
            <label class="layui-form-label">拿货数量</label>
            <div class="layui-input-inline">
                <input  name="takeAwayCount" class="layui-input" lay-verify="required|number" placeholder="请输入拿货数量">
            </div>
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-inline" style="width: 200px">
                <select name="orderId" lay-verify="required">
                    <option value="-1" id="oop">请选择订单</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">款号</label>
            <div class="layui-input-inline" style="width: 200px">
                <select name="styleId" lay-verify="required">
                    <option value="-1" id="sop" >请选择款号</option>
                </select>
            </div>
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-inline" style="width: 200px">
                <select name="productId" lay-verify="required">
                    <option value="-1" id="pop">请选择商品</option>
                </select>
            </div>
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-inline" style="width: 200px">
                <select name="materialsId" lay-verify="required">
                    <option value="-1" id="mop">请选择物料</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">

            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <textarea name="src" class="layui-textarea" placeholder="请输入备注" style="width:800px"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left:280px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitForm">申请</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/layui/2.5.7/layui.js"></script>
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form;
        var laydate = layui.laydate;

        // 初始化日期选择器
        laydate.render({
            elem: '#submitTime',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            trigger: 'click'
        });

        // 监听表单提交
        form.on('submit(submitForm)', function (data) {
            var formData = data.field;
            console.log(formData);
            let value = $('#fm').serializeArray();
            $.each(value, function(index,item){
                data[item.name] = item.value;
            });
            let con = JSON.stringify(data);
            $.ajax( {
                "url"            :  "tailor/addTakeAwaySubmit",
                "type"         :  "post",
                "data"         :  con,
                "dataType" :  "json",
                contentType:"application/json;charset=utf-8",
                "success"  :  function(result) {
                    layer.msg(result.message)
                },
                "error"       :  function() {
                    alert("添加失败")
                }
            } );
            return false; // 阻止表单提交+
        });
    });
</script>
</body>
<script type="text/javascript">
    queryId()
    function queryId() {
        $.ajax( {
            "url"            :  "tailor/queryMaterials",
            "type"         :  "get",
            "data"         :  {},
            "dataType" :  "json",
            // contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                let opo =''
                for (let ord in result) {
                    opo +=`
                    <option value="\${result[ord].materialsId}">\${result[ord].materialsName}</option>
                    `
                }
                $('#mop').after(opo)
                layui.form.render('select'); // 重新渲染select元素
            },
            "error"       :  function() {
                alert("没有查询到部门")
            }
        } );
        $.ajax( {
            "url"            :  "tailor/getProductDetail",
            "type"         :  "get",
            "data"         :  {},
            "dataType" :  "json",
            // contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                let opo =''
                for (let ord in result) {
                    opo +=`
                    <option value="\${result[ord].id}">\${result[ord].productName}</option>
                    `
                }
                $('#pop').after(opo)
                layui.form.render('select'); // 重新渲染select元素
            },
            "error"       :  function() {
                alert("没有查询到生产计划")
            }
        } );
        $.ajax( {
            "url"            :  "contract/queryOrder",
            "type"         :  "get",
            "data"         :  {},
            "dataType" :  "json",
            // contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                let opo =''
                for (let ord in result) {
                    opo +=`
                    <option value="\${result[ord].orderId}">\${result[ord].quotationNumber}</option>
                    `
                }
                $('#oop').after(opo)
                layui.form.render('select'); // 重新渲染select元素
            },
            "error"       :  function() {
                alert("没有查询到订单相关的颜色和尺寸")
            }
        } );
        $.ajax( {
            "url"            :  "tailor/queryStyleNumber",
            "type"         :  "get",
            "data"         :  {},
            "dataType" :  "json",
            // contentType:"application/json;charset=utf-8",
            "success"  :  function(result) {
                let opo =''
                for (let ord in result) {
                    opo +=`
                    <option value="\${result[ord].styleNumberId}">\${result[ord].styleNumber}</option>
                    `
                }
                $('#sop').after(opo)
                layui.form.render('select'); // 重新渲染select元素
            },
            "error"       :  function() {
                alert("没有查询该款号")
            }
        } );
    }
</script>
</html>
